UNIT Where;

(* The following MPW commands will build the dcmd and copy it to the
   "Debugger Prefs" file in the System folder. The dcmd's name in
		 MacsBug will be the name of the file built by the Linker.

	    Pascal Echo.p
	    Link dcmdGlue.a.o Echo.p.o {Libraries}Runtime.o {PLibraries}PasLib.o -o Echo
	    BuildDcmd Echo 101
*)

{$R-}

INTERFACE

		USES MemTypes, dcmds;
		
  { Public declaration for dcmdGlue. Must be in every dcmd. The name cannot be changed. }
		PROCEDURE CommandEntry (paramPtr: dcmdBlockPtr);


IMPLEMENTATION

CONST CR = $0D;


PROCEDURE CommandEntry (paramPtr: DCmdBlockPtr);
VAR address: LONGINT;
    ch:      CHAR;
				ok:      BOOLEAN;
				name:    Str255;
BEGIN
  IF paramPtr^.request = dcmdInit THEN
		  BEGIN { The dcmd gets called once when loaded to init itself }
				END
		ELSE
  IF paramPtr^.request = dcmdDoIt THEN
		  BEGIN { Do the command's normal function }
				IF dcmdPeekAtNextChar = CHR(CR) THEN
				  address := paramPtr^.registerFile^[PCRegister]
				ELSE
				  BEGIN
				  ch := dcmdGetNextExpression (address, ok);
						IF NOT ok THEN
						  BEGIN
								dcmdDrawLine ('Syntax error');
								Exit (CommandEntry);
								END;
						END;
				IF (address >= $0000A000) AND (address <= $0000ABFF) THEN
				  BEGIN
						dcmdGetTrapName (address, name);
						dcmdDrawLine (name);
						END
				ELSE
				  BEGIN
						dcmdGetNameAndOffset (address, name);
				  IF Length (name) > 0
						  THEN dcmdDrawLine (name)
								ELSE dcmdDrawLine ('No procedure name found');
						END;
				END
		ELSE
  IF paramPtr^.request = dcmdHelp THEN
		  BEGIN { Display the command's help information }
				dcmdDrawLine ('WHERE [addr | trap]');
				dcmdDrawLine ('   Display information about the address or trap');
				dcmdDrawLine ('   If no parameter then use PC as the address');
				END;
END;

END.
